home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows Expert
/
Windows Expert.iso
/
windownt
/
wpj1_8.zip
/
FDIAG.ZIP
/
FILEDIAL.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-12
|
5KB
|
220 lines
// filedial.cpp : implementation file
//
#include "stdafx.h"
#include "fdiag.h"
#include "dlgs.h" // define the resource in a file list dialog.
#include "filedial.h"
#include "string.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileDialogEx dialog
CFileDialogEx::CFileDialogEx(BOOL bOpenFileDialog,
LPCSTR lpszDefExt,
LPCSTR lpszFileName,
DWORD dwFlags,
LPCSTR lpszFilter,
CWnd* pParentWnd)
: CFileDialog(bOpenFileDialog,
lpszDefExt,
lpszFileName,
dwFlags |OFN_ENABLETEMPLATE |OFN_ALLOWMULTISELECT,
lpszFilter,
pParentWnd
)
{
//{{AFX_DATA_INIT(CFileDialogEx)
//}}AFX_DATA_INIT
m_ofn.lpTemplateName = MAKEINTRESOURCE (IDD_FILEOPENORD);
m_ofn.hInstance = AfxGetResourceHandle();
m_bAdd = FALSE;
}
CFileDialogEx::~CFileDialogEx()
{
for(int i =0; i< m_saFileList.GetSize(); i++) {
::free((char*) (const char*) m_saFileList[i]);
}
};
void CFileDialogEx::DoDataExchange(CDataExchange* pDX)
{
CFileDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileDialogEx)
DDX_Control(pDX, IDC_BUTTON2, m_btnDelete);
DDX_Control(pDX, IDC_BUTTON1, m_btnAdd);
DDX_Control(pDX, IDC_LIST1, m_FileList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileDialogEx, CFileDialog)
//{{AFX_MSG_MAP(CFileDialogEx)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON1, OnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnClickedButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileDialogEx message handlers
BOOL CFileDialogEx::OnInitDialog()
{
CFileDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CFileDialogEx::OnFileNameOK()
{
if (m_bAdd)
return TRUE; // Keep the dialog.
else
return FALSE;
// Handler for the LPOPENFILENAME;
/*static BOOL bQuit = FALSE;
if (bQuit) {
bQuit = FALSE;
if (!m_bAdd) return FALSE; // discontinue
else return TRUE; // continue
}
int cbSel;
cbSel = 1 + *((LPWORD) m_ofn.lpstrFile);
LPSTR p = (LPSTR) ::malloc(cbSel); // delet by the destructor
m_ofn.lpstrFile = p;
m_ofn.nMaxFile = cbSel;
bQuit = TRUE;
SendMessage(WM_COMMAND, IDOK, 0L);
return TRUE;
*/
};
static char* newStr(const char* s)
{
char *p = (char*) ::malloc(strlen(s)+1);
strcpy(p, s);
return p;
}
void CFileDialogEx::OnOK()
{
// TODO: Add extra validation here
CFileDialog::OnOK();
if (m_bAdd) return; // don't do anything.
// End Dialog regardless.
char sFileName[255];
for(int i =0; i< m_FileList.GetCount(); i++) {
m_FileList.GetText(i, sFileName);
m_saFileList.Add(newStr(sFileName));
}
EndDialog(IDOK);
}
void CFileDialogEx::OnDestroy()
{
CFileDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CFileDialogEx::OnClickedButton1()
{
// TODO: Add your control notification handler code here
// force the control to put the path information in the
// m_ofn.lpstrFile.
m_bAdd = TRUE;
SendMessage(WM_COMMAND, IDOK, 0L);
m_bAdd = FALSE;
char fileName[256];
CString pathName;
int nSelCount = (int) SendDlgItemMessage(lst1, LB_GETSELCOUNT, 0,
(LPARAM)0);
if (nSelCount ==0) {
MessageBox("Nothing to Add!", "WARNING",
MB_ICONEXCLAMATION|MB_OK);
return;
}
CString s;
// only one item is selected.
if (nSelCount==1) {
s = m_ofn.lpstrFile;
s.MakeLower();
if (m_FileList.FindString(0, s)==LB_ERR)
m_FileList.AddString(s);
else {
CString sWarning = "Duplicated filename " + s + "!";
MessageBox(sWarning, "WARNING",
MB_ICONEXCLAMATION|MB_OK);
}
return;
}
char* path = strtok((char*)m_ofn.lpstrFile, " ");
pathName = path;
int* lpSelItems = (int*) ::malloc(sizeof(int) * (nSelCount+1));
int ret = (int) SendDlgItemMessage(lst1, LB_GETSELITEMS,
(WPARAM) nSelCount, (LPARAM) lpSelItems);
pathName += "\\";
ASSERT(ret!=LB_ERR);
int curIdx = 0;
for (int i = 0; i < nSelCount; i++) {
curIdx = lpSelItems[i];
SendDlgItemMessage(lst1, LB_GETTEXT, curIdx, (LPARAM) (LPSTR) fileName);
s = pathName;
s += fileName;
// add string if it's not in the listbox already
s.MakeLower();
if (m_FileList.FindString(0, s)==LB_ERR)
m_FileList.AddString(s);
else {
CString sWarning = "Duplicated filename " + s + "!";
MessageBox(sWarning, "WARNING",
MB_ICONEXCLAMATION|MB_OK);
}
// TRACE("Duplicated filename %s\n", (LPCSTR)s);
}
::free(lpSelItems);
}
void CFileDialogEx::OnClickedButton2()
{
// TODO: Add your control notification handler code here
int nSelCount = m_FileList.GetSelCount();
if (nSelCount ==0) {
MessageBox("Nothing to Delete!", "WARNING",
MB_ICONEXCLAMATION|MB_OK);
return;
};
int* lpSelItems = (int*) ::malloc(sizeof(int) * (nSelCount+1));
int ret = m_FileList.GetSelItems(nSelCount, lpSelItems);
ASSERT(ret!=LB_ERR);
int curIdx = 0;
for (int i = nSelCount-1; i >=0; i--) {
curIdx = lpSelItems[i];
m_FileList.DeleteString(curIdx);
};
::free(lpSelItems);
}